function addGenerator (Blockly) {// this rule is the rule in openblock-gui/.../generator/..
    Blockly.Loongson.servo_loongbian = function (block) {
        Blockly.Loongson.imports_["loongpio"] = 'from loongpio import *'
        Blockly.Loongson.imports_["loongpio.pins"] = "from loongpio.pins import *";
        const pin = this.getFieldValue('pin') || 'PWM0';
        const degree = Blockly.Loongson.valueToCode(this,'degree',Blockly.Python.ORDER_ATOMIC); // or this.getFieldValue()
        // as the same,you can use the 
        // var level = Blockly.Loongson.valueToCode(block, 'LEVEL', Blockly.Loongson.ORDER_FUNCTION_CALL) || 'LOW';
        Blockly.Loongson.setups_[`_${pin}`] = `_${pin} = Servo(${pin})`
        var code = `_${pin}.angle = ${degree}\n`;
        return code;
    };
    Blockly.Loongson.servo_loongbian_set_min = function(block){
        Blockly.Loongson.imports_["loongpio"] = 'from loongpio import *'
        Blockly.Loongson.imports_["loongpio.pins"] = "from loongpio.pins import *";
        const pin = this.getFieldValue('pin') || 'PWM0';
        Blockly.Loongson.setups_[`_${pin}`] = `_${pin} = Servo(${pin})`
        var code = `_${pin}.min()\n`
        return code;
    };
    Blockly.Loongson.servo_loongbian_set_max = function(block){
        Blockly.Loongson.imports_["loongpio"] = 'from loongpio import *'
        Blockly.Loongson.imports_["loongpio.pins"] = "from loongpio.pins import *";
        const pin = this.getFieldValue('pin') || 'PWM0';
        Blockly.Loongson.setups_[`_${pin}`] = `_${pin} = Servo(${pin})`
        var code = `_${pin}.max()\n`
        return code;
    };
    Blockly.Loongson.servo_loongbian_set_mid = function(block){
        Blockly.Loongson.imports_["loongpio"] = 'from loongpio import *'
        Blockly.Loongson.imports_["loongpio.pins"] = "from loongpio.pins import *";
        const pin = this.getFieldValue('pin') || 'PWM0';
        Blockly.Loongson.setups_[`_${pin}`] = `_${pin} = Servo(${pin})`
        var code = `_${pin}.mid()\n`
        return code;
    };
    return Blockly;
}

exports = addGenerator;